<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Booking_model
 * Build by Phuc Nguyen
 * Contact : nguyenvanphuc0626@gmail.com
 */

class Booking_model extends MY_Model{
	
	public function __construct(){
		parent::__construct();
		$this->table_name = 'book_list_booking';
	}
        
        public function getListBookingTypes(){
            return $this->booking_types;
        }
        
        public function getListBank(){
            $result[0]  = '------- Vui lòng chọn -------';
            foreach($this->booking_model->getListBanks() as $keys => $values){
                $result[$values->id] = $values->bank_name;
            }
            return $result;
        }
        
        public function getListBookingById($params){
            $this->db->select('customerID');
            $this->db->from($this->table_name);
            $this->db->where('customerID',$params);
            $query = $this->db->get();
            return $query->result();
        }
        
        public function udpate_confirm($params){
            $sql    = "UPDATE {$this->table_name} SET payment_confirm = 1,real_fare = '".$params['amount']."' WHERE id = '".$params['booking_id']."'";
            $this->db->query($sql);
            return $this->db->affected_rows();
        }
        
        public function searchBooking($table,$name=NULL,$phone=NULL,$booking_place_code=NULL){
            $this->db->select('tbl.*,bc.name,bc.phone');
            $this->db->from($table . ' AS tbl');
            $this->db->join('book_contacts AS bc','tbl.customerID = bc.customerID');

            if($name){
                $this->db->where('tbl.booking_customer_name REGEXP ("'.$name.'")');
            }
            if($phone){
                $this->db->like('bc.phone',$phone);
            }
            if($booking_place_code){
                $this->db->where('booking_place_code',$booking_place_code);
            }
            $this->db->order_by('createdTime','DESC');
            $query = $this->db->get();
//            echo $this->db->last_query();exit;
            return $query->result();
        }
        
        public function bookinghold($params){
            $this->db->select('count(*) AS count');
            $this->db->from($this->table_name);
            $this->db->where('owner',$params);
            $query = $this->db->get();
            return $query->result();
        }
}